package com.lagou.concurrent.demo;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.Supplier;

public class CompletableFutureDemo7 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(new Supplier<String>() {
            @Override
            public String get() {
                return "hello lagou";
            }
        }).thenCompose(new Function<String, CompletableFuture<Integer>>() {
            @Override
            public CompletableFuture<Integer> apply(String s) {
                return CompletableFuture.supplyAsync(new Supplier<Integer>() {
                    @Override
                    public Integer get() {
                        return s.length();
                    }
                });
            }
        });

        System.out.println(future.get());

    }

//    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        CompletableFuture<CompletableFuture<Integer>> future
//                = CompletableFuture.supplyAsync(new Supplier<String>() {
//            @Override
//            public String get() {
//                return "hello lagou";
//            }
//        }).thenApply(new Function<String, CompletableFuture<Integer>>() {
//            @Override
//            public CompletableFuture<Integer> apply(String s) {
//                return CompletableFuture.supplyAsync(new Supplier<Integer>() {
//                    @Override
//                    public Integer get() {
//                        return s.length();
//                    }
//                });
//            }
//        });
//
//        Integer integer = future.get().get();
//        System.out.println(integer);
//
//    }
}
